package cn.itcast.order;

import cn.itcast.feign.clients.UserClient;
import cn.itcast.feign.config.DefaultFeignConfiguration;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@MapperScan("cn.itcast.order.mapper")
@SpringBootApplication
//开启feign的自动装配功能
@EnableFeignClients(clients = UserClient.class,defaultConfiguration = DefaultFeignConfiguration.class)
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }

    //注册
    //通过@Bean的方式将RestTemplate注册为spring的对象，以后在任何地方都可注入此对象直接使用
//    @Bean
//    //@LoadBalanced负载均衡注解
//    @LoadBalanced
//    public RestTemplate restTemplate(){
//        return new RestTemplate();
//    }

    /**
     * 修改eureka的负载均衡策略，这里设置为随机选择
     * 这里是方式一，方式二是在order-service的application.yml中配置
     * @return
     */
//    @Bean
//    public IRule randomRule(){
//        return new RandomRule();
//    }

}